package net.hvacapp.cmvrfforandroid.manager;

import com.mirror.android.common.util.StringUtils;

import net.hvacapp.cmvrfforandroid.ui.project.model.ProjectInfoData;

/**
 * Created by zhangnorman on 15/7/23.
 */
public class ProjectManager {

    //    状态
    public static final int PROJECT_STATUS_NEW = 0; //新建项目
    public static final int PROJECT_STATUS_NEW_HAS_CREATED = 1; //新建项目，项目已经创建成功
    public static final int PROJECT_STATUS_MODIFY = 2; //修改项目

    private static ProjectManager mInstance = null;


    private ProjectInfoData projectData;
    private int total = 9; //总步数
    private int current = 1; //当前步数

    private int status;

    private boolean isBindTemplate; //是否绑定了模板


    /**
     *

     系统配置中：

     1.室外机开关关闭
     房间中，室内设备不允许添加室内机，室外机系统配置不允许

     2.轻型商用空调开关关闭
     房间中，室内设备不允许添加轻型商用空调。

     3.如果室外机开关和轻型商用空调开关均关闭
     不显示房间信息页面和室外机系统配置页面。

     4.空气能热水机开关关闭
     不显示空气能配置页面

     5.全热交换器开关关闭
     不显示全热交换器页面配置

     */
    private boolean swjEnable; //项目中室外机的开关是否打开
    private boolean qxsyktEnable; //项目中轻型商用空调的开关是否打开
    private boolean kqnrsjEnable; //项目中空气能热水机的开关是否打开
    private boolean qrjhqEnable; //项目中全热交换器的开关是否打开

    private String snjSeries; //项目中默认选择的室内机系列ID
    private String swjSeries; //项目中默认选择的室外机系列ID
    private String qxsyktSeries; //项目中默认选择的轻型商用空调系列ID
    private String kqnrsjSeries; //项目中默认选择的空气能热水机系列ID
    private String qrjhqSeries; //项目中默认选择的全热交换器系列ID


    public boolean isSwjEnable() {
        return swjEnable;
    }

    public void setSwjEnable(boolean swjEnable) {
        this.swjEnable = swjEnable;
    }

    public boolean isQxsyktEnable() {
        return qxsyktEnable;
    }

    public void setQxsyktEnable(boolean qxsyktEnable) {
        this.qxsyktEnable = qxsyktEnable;
    }

    public boolean isKqnrsjEnable() {
        return kqnrsjEnable;
    }

    public void setKqnrsjEnable(boolean kqnrsjEnable) {
        this.kqnrsjEnable = kqnrsjEnable;
    }

    public boolean isQrjhqEnable() {
        return qrjhqEnable;
    }

    public void setQrjhqEnable(boolean qrjhqEnable) {
        this.qrjhqEnable = qrjhqEnable;
    }



    // 懒汉式单例
    public static synchronized ProjectManager getInstance() {
        if (mInstance == null) {
            mInstance = new ProjectManager();
        }
        return mInstance;
    }

    public void initData() {
        total = 9;
        if (isBindTemplate) {
            total--;
        }
        current = 1;
        swjEnable = false;
        qxsyktEnable = false;
        kqnrsjEnable = false;
        qrjhqEnable = false;
    }


    public ProjectInfoData getProjectData() {
        if (projectData == null) {
            projectData = new ProjectInfoData();
        }
        return projectData;
    }

    public void setProjectData(ProjectInfoData projectData) {
        this.projectData = projectData;
    }

    public int getTotal() {
//        total = 9;
        return total;
    }

    public int getCurrent() {
        return current;
    }



    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        if (status == PROJECT_STATUS_MODIFY) {
            isBindTemplate = true;
        }
        this.status = status;
    }

    public boolean isBindTemplate() {
        return isBindTemplate;
    }

    public void setIsBindTemplate(boolean isBindTemplate) {
        this.isBindTemplate = isBindTemplate;
    }

    public void goNextStep() {
        if (current < total) {
            current++;
        }
    }

    public void goLastStep() {
        if (current > 0) {
            current--;
        }
    }

    public void setProjectSeriesEnable(String tag, boolean flag) {
        if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_SWJ)) {
            swjEnable = flag;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QXSYKT)) {
            qxsyktEnable = flag;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_KQNRSJ)) {
            kqnrsjEnable = flag;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QRJHQ)) {
            qrjhqEnable = flag;
        }
    }

    public boolean snjDeviceEnabled() {
        return swjEnable;
    }

    public boolean qxsyktDeviceEnabled() {
        return qxsyktEnable;
    }

    public boolean swjPageEnabled() {
        return swjEnable;
    }

    public boolean roomPageEnabled() {
        boolean isEnable = true;
        if (!swjEnable && !qxsyktEnable) {
            isEnable = false;
        }
        return isEnable;
    }

    public boolean kqnrsjPageEnabled() {
        return kqnrsjEnable;
    }

    public boolean qrjhqPageEnabled() {
        return qrjhqEnable;
    }

    public void updateTotalSteps() {
        total = 9;
        if (!roomPageEnabled()) {
            total--;
        }
        if (!swjPageEnabled()) {
            total--;
        }
        if (!kqnrsjPageEnabled()) {
            total--;
        }
        if (!qrjhqPageEnabled()) {
            total--;
        }
        if (isBindTemplate()) {
            total--;
        }
    }

    public void setProjectDefaultSeries(String tag, String series) {
        if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_SWJ)) {
            swjSeries = series;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QXSYKT)) {
           qxsyktSeries = series;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_KQNRSJ)) {
            kqnrsjSeries = series;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QRJHQ)) {
            qrjhqSeries = series;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_SNJ)) {
            snjSeries = series;
        }
    }

    public String getProjectDefaultSeries(String tag) {
        if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_SWJ)) {
            return swjSeries;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QXSYKT)) {
            return qxsyktSeries;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_KQNRSJ)) {
            return kqnrsjSeries;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_QRJHQ)) {
            return qrjhqSeries;
        } else if (StringUtils.isEquals(tag, ProjectInfoData.MACHINE_TAG_FOR_SNJ)) {
            return snjSeries;
        }
        else {
            return "";
        }
    }

    public void logout() {
        initData();
        projectData = null;
    }

}
